﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassFolio.Model;
using OraFolio.Gates;
using ClassFolio;
using ClassFolio.Dict;
using System.IO;

namespace GeneFolio
{
    public sealed class AreaWork
    {
        public static void LoginAs(string login, string password, string source)
        {
            IAreaWorkGate areaWork = Gates.AreaWorkGate();
            if (areaWork.Connect(login, password, source))
            {
                // Инициализация статических переменных классов предметной области
                User.UserGate = Gates.UserGate();
                User logonUser = User.CreateUserById(areaWork.getUserId(login));
                User.LogonUser = logonUser;
                Sequence.SqlGate = Gates.SqlGate();

                Role.RoleGate = Gates.RoleGate();
                Role.LogonUser = logonUser;
				Dept.DeptGate = Gates.DeptGate();
				Dept.LogonUser = logonUser;

				// Инициализация системы безопасности
				areaWork.GetActionsForUser(User.LogonUser);

				// Инициализация настроек
				Adjustment.AdjustmentFile = 
					String.Format("{0}\\{1}\\{2}", Adjustment.AppDir, logonUser.UserLogin, "Settings.adj");
				Adjustment.Reload();
	        }
        }

        // Private
        private static class Gates
        {
            public static IAreaWorkGate AreaWorkGate()
            {
                if (CheckGate() == TypeGate.oracle)
                    return new OraAreaWorkGate();
                return null;
            }
            public static IUserGate UserGate()
            {
                if (CheckGate() == TypeGate.oracle)
                    return new OraUserGate();
                return null;
            }
            public static IRoleGate RoleGate()
            {
                if (CheckGate() == TypeGate.oracle)
                    return new OraRoleGate();
                return null;
            }
            public static ISqlGate SqlGate()
            {
                if (CheckGate() == TypeGate.oracle)
                    return new OraSqlGate();
                return null;
            }
			public static IDeptGate DeptGate()
			{
				if (CheckGate() == TypeGate.oracle)
					return new OraDeptGate();
				return null;
			}
		}
        private static TypeGate CheckGate()
        {
            return TypeGate.oracle;
        }
        private enum TypeGate { oracle }
		private void test()
		{
			System.Windows.Media.Color cl = System.Windows.Media.Colors.White;
		}
    }

}
